import re


def extract_table_names_from_sql_file(file_path):
    table_names = []
    # 正则表达式匹配模式
    pattern = r'CREATE\s+TABLE\s+"?\w+"?\."?(\w+)"?'

    with open(file_path, 'r', encoding='utf-8') as file:
        content = file.read()
        # 使用正则表达式查找所有匹配项
        matches = re.findall(pattern, content)
        for match in matches:
            if match not in table_names:  # 避免重复
                table_names.append(match)

    return table_names

# 使用函数
file_path = 'D:/06git/01python/02vanna/02导入训练sql数据/smartlight/data/smartlight-simple2.sql'
table_names = extract_table_names_from_sql_file(file_path)


print(table_names)